import allure
from selenium.webdriver.common.by import By

from base.base_action import BaseAction
import time
import allure
import pytest

from base.base_driver import InitDriver



class Login(BaseAction):

    driver = InitDriver().get_driver()
    # 账户名
    user_name = By.CLASS_NAME, "el-input__inner"

    # 密码
    password = By.XPATH, '//*[@id="app"]/div/div[2]/form/div[2]/div/div/input'

    # 登录
    btn_login = By.XPATH, "//span"

    # 输入用户名
    @allure.step(title='输入用户名')
    def input_user_name(self, text):
        return self.input(self.user_name, text)

    # 输入密码
    @allure.step(title='输入密码')
    def input_pwd(self, text):
        return self.input(self.password, text)

    # 点击登录
    @allure.step(title='点击登录')
    def click_login(self):
        return self.click(self.btn_login)

    def login_web(self,name,pwd):
        self.driver.get(self.base_url() + "/#/login")
        for i in range(5):
            self.input_user_name(name)
            # 输入密码
            self.input_pwd(pwd)
            # 点击登录
            self.click_login()
            text = self.find_by_text_span("居民管理")
            if text == "居民管理":
                return True
